var next_page=0,page=1;
var index;
Page({
  data: {
    jigou_id:"",
      markers: [],
      mch_id:"",
      statusbar: 0,
      user_id: 0,
      user: {},
      list: [],
      article: {},
      is_detail_show: 0,
      headshow: 0,
      listcont:"",





    aaa:false,
    class:"",
    statusbar: 0,
    user_id: 0,
    user: {},
    list: [],
    article: {},
    is_detail_show: 0,
    headshow: 0,
    // 消息小红点
    message: 0,
    statusbar: 0,
  },


  callPhone: function (t) {
    getApp().core.makePhoneCall({
        phoneNumber: t.target.dataset.info
    });
},

  classfenlei:function(){
    console.log(this.__data__.mch_id,'tttttttttt')
      var id=this.__data__.mch_id;
    wx.redirectTo({
      url: '/mch/shop-cat/shop-cat?mch_id=' + id,
    })
  },
  shouye:function(){
    console.log(this.__data__.mch_id,'tttttttttt')
    var id=this.__data__.mch_id;
    wx.redirectTo({
      url: '/mch/shop/shop?mch_id=' + id,
    })
  },
  jieshao:function(){
    console.log(this.__data__.mch_id,'tttttttttt')
    var id=this.__data__.mch_id;
    wx.redirectTo({
      url: '/mch/shop-summary/shop-summary?mch_id=' + id,
    })
  },
  js:function(){
    wx.redirectTo({
      url: '/mch/institutional-community/institutional-community',
    })
  }
,  zhibo:function(){
  console.log(this.__data__.mch_id,'tttttttttt')
  var id=this.__data__.mch_id;
    wx.redirectTo({
      url: '/lives/admin/goods-list/goods-list?mch_id=' + id,
    })
  },
  shequn:function(){

  },
  zk:function(){
    this.setData({
      aaa:false,
      class:""
    })
  },
  sq:function(){
    this.setData({
      aaa:true,
      class:"aa"
    })
  },
  bianji:function(e){
    console.log(e.currentTarget.dataset.articleId)
    var id=e.currentTarget.dataset.articleId;
  wx.navigateTo({
    url: '/weitao/publish/publish?articleId='   +id   ,
  })

  },


//跳转页面
goUrl: function (e) {
  var gopage = e.currentTarget.dataset.url,
    s = this;
  if (!gopage) {
    return;
  }
  console.log(gopage, "去");
  wx.navigateTo({
    url: gopage,
    events: {
      someEvent: function (data) {
        console.log('返回了');
        s.loadData();
      }
    },
    success: function (res) {}
  })
},
loadData: function (t) { console.log('加载')
var a = this;
wx.showShareMenu({
  withShareTicket: true,
  menus: ['shareAppMessage', 'shareTimeline']
})
getApp().core.showLoading({
  title: "加载中"
}), getApp().request({
  url: getApp().api.weitao.index,
  data: {
    city_name: a.data.region.name,
    city_id: a.data.region.id,
    id: a.data.region.id
  },
  success: function (t) {
    console.log(t)
    0 == t.code && a.setData({
      list: t.data.listcont[a.data.pitch],
      user: t.data.user,
      referrer: t.data.referrer,
      ask_answer: t.data.ask_answer,
      listcont: t.data.listcont,
      message: t.data.message,
    });
  },
  complete: function () {
    getApp().core.hideLoading();
  }
});
},
getUser: function () {
  var t = this
  console.log(t,'数据啊1')
  console.log(t.__data__.jigou_id,'机构id')
  getApp().core.showLoading({}), getApp().request({
    url: getApp().api.weitao.index,
    data: {
      
      // user_id: t.data.user_id
      // mch_id:t.data.jigou_id
      mch_id:t.options.mch_id
    },
    method: "get",
    success: function (e) {
      console.log(e,'数据回调成功')
      // getApp().core.hideLoading()
      // if (0 == e.code) {
      //   var i = t.data.list,
      //     s = e.data.list,
      //     n = !1;
      //   10 == s.length && (n = 1), i = i.concat(s), page++, 
      t.setData({
          list: e.data.listcont[0],
          user: e.data.user
        });
        
        // next_page = n;
      // } else getApp().core.showToast({
      //   title: e.msg,
      //   icon: 'none'
      // });
    },
    fali: function (t) {
      getApp().core.hideLoading()
      getApp().core.showToast({
        title: t.msg,
        icon: 'none'
      });
    }
  });
},
/**
 * 
 * @param {*} e 
 * 关注
 */
focus_action(e) {
  var user_id = this.data.user.user_id,
    s = this;
  var like_data = 0;
  s.data.user.is_user_liked == 1 ? like_data = 2 : like_data = 1;
  if (user_id > 0) {
    var a = this;
    getApp().core.showLoading({
      title: "加载中"
    }), getApp().request({
      url: getApp().api.weitao.focus_user,
      data: {
        user_id: user_id,
        is_user_liked: like_data
      },
      success: function (t) {
        0 == t.code && (s.data.user.is_user_liked = like_data) && a.setData({
          user: s.data.user
        });
        console.log(s.data.user);
        getApp().core.showToast({
          title: t.msg,
          icon: 0 == t.code ? 'success' : 'none'
        });
      },
      complete: function () {
        getApp().core.hideLoading();
      }
    });
  } else {
    getApp().core.showToast({
      title: "系统错误",
      icon: 'none'
    });
  }
},
share_return() {
  return false;
},
like_action(e) {
  var user_index = e.currentTarget.dataset.userIndex,
    s = this,
    article = s.data.list[user_index];
  var like_data = 0;
  article.is_liked == 1 ? like_data = 0 : like_data = 1;
  let like_count = article.like_count;
  if (article.id > 0) {
    var a = this;
    getApp().core.showLoading({
      title: "加载中"
    }), getApp().request({
      url: getApp().api.weitao.like_article,
      data: {
        article_id: article.id,
        is_liked: like_data
      },
      success: function (t) {
        if (t.code == 0) {
          s.data.list[user_index].is_liked = like_data;
          if (like_data == 1) {
            s.data.list[user_index].like_count = parseInt(like_count) + 1;
          } else {
            if (parseInt(like_count) > 1) {
              s.data.list[user_index].like_count = parseInt(like_count) - 1;
            } else {
              s.data.list[user_index].like_count = 0;
            }
          }
          a.setData({
            list: s.data.list
          });
        }
        getApp().core.showToast({
          title: t.msg,
          icon: 'none'
        });
      },
      complete: function () {
        getApp().core.hideLoading();
      }
    });
  } else {
    getApp().core.showToast({
      title: "系统错误",
      icon: 'none'
    });
  }
},

onUnload(){ 
  const eventChannel = this.getOpenerEventChannel()
  eventChannel.emit('someEvent', 1);
},
deleteArticle(e) {
  var article_id = e.currentTarget.dataset.articleId,
    index = e.currentTarget.dataset.index,
    s = this;
  if (article_id > 0) {
    wx.showModal({
      title: '提示',
      content: '是否删除？',
      confirmText: "删除",
      success(res) {
        if (res.confirm) {
          getApp().core.showLoading({
            title: "加载中"
          }), getApp().request({
            url: getApp().api.weitao.delete_article,
            data: {
              article_id: article_id,
            },
            success: function (t) {
              s.data.list.splice(index, 1);
              if (t.code == 0) {
                s.setData({
                  list: s.data.list
                });
                // s.getUser();
              }
              getApp().core.showToast({
                title: t.msg,
                icon: 'none'
              });
            },
            complete: function () {
              getApp().core.hideLoading();
            }
          });


        }
      }
    })

  } else {
    getApp().core.showToast({
      title: "系统错误",
      icon: 'none'
    });
  }
},

//跳转页面
goUrl: function (e) {
  var gopage = e.currentTarget.dataset.url;
  if (!gopage) {
    return;
  }
  getApp().core.navigateTo({
    url: gopage
  });
},
goBack() {
  wx.navigateBack({
    delta: 1
  })
},
show_detail(e) {
  var article = {};
  if (e.currentTarget.dataset.article && this.data.is_detail_show != 1) {
    article = e.currentTarget.dataset.article;
    article.head_url = article.from_user_head;
    article.nickname = article.from_user_name;
    article.is_user_liked = article.is_focused;
  }
  this.setData({
    article: article,
    is_detail_show: this.data.is_detail_show == 1 ? 0 : 1
  });
},
onPageScroll: function (e) {
  let opacity = 0
  if (e.scrollTop <= 200) {
    opacity = e.scrollTop / 200
  } else {
    opacity = 1
  }
  this.setData({
    headshow: opacity
  })
},


    onLoad: function (t) {
      // this.loadData();
    var that=this;
    console.log(this,'onload全')
    console.log(t,'oooooooo')
      getApp().page.onLoad(that, t), t.mch_id && (that.setData({
          mch_id: t.mch_id
      }), that.getShopData());
      const res = wx.getSystemInfoSync()
      wx.showShareMenu({
        withShareTicket: true,
        menus: ['shareAppMessage', 'shareTimeline']
      })
      var statusbarH = res.statusBarHeight
      this.setData({
        statusbar: statusbarH
      })
      getApp().page.onLoad(this, t),page = 1;
      if (t.user_id) {
        this.setData({
          user_id: t.user_id
        });
      }
      this.getUser()
          
  },
  kfuStart: function () {
      this.setData({
          copy: !0
      });
  },
  kfuEnd: function () {
      this.setData({
          copy: !1
      });
  },
  copyinfo: function (t) {
      getApp().core.setClipboardData({
          data: t.target.dataset.info,
          success: function (t) {
              getApp().core.showToast({
                  title: "复制成功！",
                  icon: "success",
                  duration: 2e3,
                  mask: !0
              });
          }
      });
  },
  callPhone: function (t) {
      getApp().core.makePhoneCall({
          phoneNumber: t.target.dataset.info
      });
  },
  onShow: function () {
      getApp().page.onShow(this);
  },
  getShopData: function () {
      var a = this;
      getApp().core.showLoading({
          title: "加载中"
      }), getApp().request({
          url: getApp().api.mch.shop_introduce,
          data: {
              mch_id: a.data.mch_id
          },
          success: function (t) {
            console.log(t,'jigou')
            console.log(t.data.shop.user_id,'jigou_id')

              if (0 == t.code) {
                  var e = t.data.shop,
                      o = [{
                          iconPath: "/mch/images/img-map.png",
                          id: 0,
                          width: 20,
                          height: 43,
                          longitude: e.longitude,
                          latitude: e.latitude
                      }];
                  a.setData({
                      markers: o,
                      shop: t.data.shop,
                      cs_icon: t.data.shop.cs_icon,
                      jigou_id:t.data.shop.user_id
                  });
              }
          },
          complete: function () {
              getApp().core.hideLoading(), a.setData({
                  loading: !1
              });
          }
      });
  },
  map_power: function () {
      var o = this;
      console.log(o,'位位')
      getApp().getConfig(function (t) {
        console.log(t,'位置')
        
          // var e = o.data.shop;
          var e= o.__data__.shop;
          void 0 !== e ? o.map_goto(e) : getApp().core.getSetting({
              success: function (t) {
                console.log(t,'位置2')
                  t.authSetting["scope.userLocation"] ? o.map_goto(e) : getApp().getauth({
                      content: "需要获取您的地理位置授权，请到小程序设置中打开授权！",
                      cancel: !1,
                      author: "scope.userLocation",
                      success: function (t) {
                          t.authSetting["scope.userLocation"] && o.map_goto(e);
                      }
                  });
              }
          });
      });
  },
  map_goto: function (t) {
      getApp().core.openLocation({
          latitude: parseFloat(t.latitude),
          longitude: parseFloat(t.longitude),
          address: t.address
      });
  },
  onClickImage: function () {
      wx.previewImage({
          current: this.data.shop.business,
          urls: [this.data.shop.business]
      });
  },
  onClick: function () {
      wx.navigateTo({
        url: '/pages/search/search?mch_id='+this.data.mch_id,
      })
  },
  onShareAppMessage: function () {
      getApp().page.onShareAppMessage(this);
      var t = this;
      return {
        path: "/mch/shop/shop?user_id=" + getApp().getUser().id + "&mch_id=" + t.data.mch_id + '&store_id=' + (wx.getStorageSync("store_id") ? wx.getStorageSync("store_id") : 0),
        title: t.data.shop ? t.data.shop.name : "店铺首页"
      };
  },
});